# -*- coding: utf-8 -*-
import re
import datetime
from openpyxl import load_workbook
import os
import getpath
import logging
import config_json
import json
def yearbeforeday(d):
    try:
        d1 = datetime.datetime(d.year + 1, d.month, d.day)
        d1 = d1 + datetime.timedelta(-1)
    except ValueError as e:
        d1 = datetime.datetime(d.year + 1, d.month, d.day - 1)
        d1 = d1 + datetime.timedelta(-1)
    return d1


def set_cell(table, row, col, value):
    # logging.info(row, col, value)
    table.cell(row=row, column=col, value=value)


def get_cell(table, row, col):
    return table.cell(row=row, column=col).value


def gen_jiao_zhun(fn):
    xl_book = load_workbook(filename=fn)
    ffbh = getSheet(xl_book, 2)
    syy = getSheet(xl_book, 3)
    ysry = getSheet(xl_book, 4)
    yqbh = getSheet(xl_book, 5)
    return (ffbh, syy, ysry, yqbh)


def getSheet(xlBook, at):
    ffbh = []
    table = xlBook.worksheets[at]
    rows = table.rows
    for row in rows:
        cell = row[0]
        ffbh.append(cell.value)
    return ffbh


def getData():
    fullfilepath = os.path.join(getpath.getpath(), "ffbh.xlsx")
    logging.info(fullfilepath)
    data = gen_jiao_zhun(fullfilepath)
    return data
def update_syy():
    ry="""lijing
houyanxia
liliguo
limeihui
liuxinxin
zhangdi
xielipeng
wangzhiqing
liumeng
liucairong
qiaolili
zhangzhenhuan
chenpeipei
baiyusen
mengqingrong
loujinhui
wangzhao
zhujingyi
yinhaizhen"""
    all=ry.split("\n")
    config_json.read_setting()
    for one in all:
        if one!="":
            if one in config_json.setting["syy"]:
                pass
            else:
                config_json.setting["syy"].append(one)
    config_json.write_setting()
def updatecs():
    config_json.read_setting()
    f=open("new_cs.txt",encoding="utf-8")
    all=f.read().split("\n")
    f.close()
    for one in all:
        if one!="":
            if one in config_json.setting["ffbh_cs"]:
                pass
            else:
                config_json.setting["ffbh_cs"].append(one)
    f=open("new_onh.txt",encoding="utf-8")
    all=f.read().split("\n")
    f.close()
    for one in all:
        if one!="":
            if one in config_json.setting["ffbh_onh"]:
                pass
            else:
                config_json.setting["ffbh_onh"].append(one)
    config_json.write_setting()
def to_text():
    config_json.read_setting()
    logging.info(config_json.setting)
    # f=open("setting.txt","w",    encoding="utf-8")
    # f.write(json.dumps(config_json.setting))
    # f.close()
def initff():
    ff="""ASTM E415-21
ASTM E1086-14
GB/T 4336-2016
GB/T 11170-2008
ASTM E3047-16
GB/T 38939-2020
GB/T 7999-2015
ASTM E1251-17a
ASTM E1086-22
GB/T24234-2009
GB/T 24234-2009
ASTM E2209-22
ASTM E3047-22"""
    config_json.read_setting()
    all=ff.split("\n")
    config_json.setting["ffbh"]=[]
    for one in all:
        if one!="":
            config_json.setting["ffbh"].append(one)
    config_json.write_setting()

def updateff():
    ff="""ASTM E415-21
ASTM E1086-14
GB/T 4336-2016
GB/T 11170-2008
ASTM E3047-16
GB/T 38939-2020
GB/T 7999-2015
ASTM E1251-17a
ASTM E1086-22
GB/T24234-2009
GB/T 24234-2009
ASTM E2209-22
ASTM E3047-22"""
    config_json.read_setting()
    all=ff.split("\n")
    for one in all:
        if one!="":
            if one in config_json.setting["ffbh"]:
                pass
            else:
                config_json.setting["ffbh"].append(one)
    config_json.write_setting()
if __name__ == "__main__":
    # updatecs()
    # update_syy()
    initff()
    # updateff()
